home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™94 / Miscellaneous / Randy Thelen / ThreadedSort / AppSpecific / DocWindow.cp < prev    next >
Encoding:
Text File  |  1994-06-26  |  2.6 KB  |  156 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        DocWindow.cp
  3.  
  4.     Contains:    A simple document window
  5.                 
  6.     Written by: Dave Falkenburg
  7.     
  8.     Copyright:    © 1993-94 by Dave Falkenburg, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.     
  12.     To Do:        Figure out what needs to move to TWindow
  13.  */
  14.  
  15. #include "DocWindow.h"
  16. #include "AppLib.h"
  17. #include <LowMem.h>    //    for LMGetCurApName()
  18.  
  19. const short    kScrollbarWidth = 15;
  20.  
  21.  
  22. TDocWindow::TDocWindow()
  23.     {
  24.     CreateWindow(kNormalWindow);
  25.     }
  26.  
  27. TDocWindow::~TDocWindow()
  28.     {
  29.     }
  30.  
  31.     
  32. WindowPtr
  33. TDocWindow::MakeNewWindow(WindowPtr behindWindow)
  34.     {
  35.     WindowPtr    theNewWindow = GetNewWindow(128,nil,behindWindow);
  36.     Str255        titleString;
  37.     static long    documentCount = 0;
  38.     
  39.     NumToString(documentCount++, titleString);
  40.     SetWTitle(theNewWindow,titleString);
  41.     ShowWindow(theNewWindow);
  42.     
  43.     return theNewWindow;
  44.     }
  45.  
  46.  
  47. void
  48. TDocWindow::Activate(Boolean /* activating */)
  49.     {
  50.     DrawGrowIcon(fWindow);
  51.     }
  52.  
  53.  
  54. void
  55. TDocWindow::AdjustCursor(EventRecord * /* anEvent */)
  56.     {
  57.     }
  58.  
  59.  
  60. void
  61. TDocWindow::Draw(void)
  62.     {
  63.     EraseRect(&fWindow->portRect);
  64.  
  65.     DrawGrowIcon(fWindow);
  66.     }
  67.  
  68.     
  69. void
  70. TDocWindow::Click(EventRecord * /* anEvent */)
  71.     {
  72.     this->Select();
  73.     }
  74.  
  75. void
  76. TDocWindow::KeyDown(EventRecord * /* anEvent */)
  77.     {
  78.     this->Select();
  79.     }
  80.  
  81.  
  82. void
  83. TDocWindow::AdjustForNewWindowSize(Rect *oldSize,Rect * /* newSize */)
  84.     {
  85.     Rect    scrollbarRect;
  86.     
  87.     //    Invalidate the old vertical scroll bar
  88.     
  89.     scrollbarRect.top = oldSize->top;
  90.     scrollbarRect.left = oldSize->right - kScrollbarWidth;
  91.     scrollbarRect.bottom = oldSize->bottom;
  92.     scrollbarRect.right = oldSize->right;
  93.     InvalRect(&scrollbarRect);
  94.  
  95.     //    Invalidate the old horizontal scroll bar
  96.  
  97.     scrollbarRect.left = oldSize->left;
  98.     scrollbarRect.top = oldSize->bottom - kScrollbarWidth;
  99.     InvalRect(&scrollbarRect);
  100.  
  101.     DrawGrowIcon(fWindow);    
  102.     }
  103.  
  104.  
  105. Boolean
  106. TDocWindow::Close(void)
  107.     {
  108.     StandardCloseResult    result;
  109.     Str255                title;
  110.     
  111.     GetWTitle(this->fWindow,title);
  112.     result = StandardCloseDocument(LMGetCurApName(),title,false,false);
  113.  
  114.     if (result != kCancelSaveDocument)
  115.         {
  116.         return TWindow::Close();
  117.         }
  118.     return false;
  119.     }
  120.  
  121.  
  122. OSErr
  123. TDocWindow::HandleDrag(DragTrackingMessage dragMessage,DragReference theDrag)
  124.     {
  125.     RgnHandle    hiliteRgn = NewRgn();
  126.     
  127.     switch (dragMessage)
  128.         {
  129.         case    dragTrackingEnterWindow:
  130.             SetRectRgn( hiliteRgn,
  131.                         fWindow->portRect.left,
  132.                         fWindow->portRect.top,
  133.                         fWindow->portRect.right-kScrollbarWidth,
  134.                         fWindow->portRect.bottom-kScrollbarWidth);
  135.             ShowDragHilite(theDrag,hiliteRgn,true);
  136.             break;
  137.             
  138.         case    dragTrackingLeaveWindow:
  139.             HideDragHilite(theDrag);
  140.             break;
  141.             
  142.         default:
  143.             break;
  144.         }
  145.     
  146.     DisposeRgn(hiliteRgn);
  147.     return(noErr);
  148.     }
  149.  
  150.     
  151. OSErr
  152. TDocWindow::HandleDrop(DragReference /* theDrag */)
  153.     {
  154.     return(noErr);
  155.     }
  156.